package com.encryption.controls
{
	import flash.display.DisplayObject;
	
	import mx.containers.Form;
	
	public class AdvancedForm extends Form
	{
		private var measuredLabelWidth:Number;
		
		public function AdvancedForm()
		{
			super();
		}
		
		/**
		 *  @private
		 */
		public function calculateLabelWidth():Number
		{
			// See if we've already calculated it.
			if (!isNaN(measuredLabelWidth))
				return measuredLabelWidth;
			
			var labelWidth:Number = 0;
			var labelWidthSet:Boolean = false;
			
			// Determine best label width.
			var n:int = numChildren;
			for (var i:int = 0; i < n; i++)
			{
				var child:DisplayObject = getChildAt(i);
				
				if (child is AdvancedFormItem && AdvancedFormItem(child).includeInLayout)
				{
					labelWidth = Math.max(labelWidth,
						AdvancedFormItem(child).getPreferredLabelWidth());
					// only set measuredLabelWidth yet if we have at least one FormItem child
					labelWidthSet = true;
				}
			}
			
			if (labelWidthSet)
				measuredLabelWidth = labelWidth;
			
			return labelWidth;
		}
	}
}